package com.sm.irun.smsintercepter;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

/***
 * @author huangsm
 * @date 2012-10-10
 * @email huangsanm@gmail.com
 * @desc 短信拦截
 */
public class SMSIntercepterReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		try {
			System.out.println("isOrderedBroadcast:" + isOrderedBroadcast());
			Bundle params = intent.getExtras();
			Object[] message = (Object[]) params.get("pdus");
			SmsMessage[] messages = new SmsMessage[message.length];
			for (int i = 0; i < message.length; i++) {
				messages[i] = SmsMessage.createFromPdu((byte[]) message[i]);
			}
			
			for (int i = 0; i < messages.length; i++) {
				SmsMessage msg = messages[i];
				System.out.println("address:" + msg.getOriginatingAddress());
				System.out.println("address:" + msg.getMessageBody());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
